<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!-- jQplot CSS -->
<link rel="stylesheet" media="screen" href="css/Tree.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/tipswindown.css"/>
<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<%-- <script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script> --%>
<script type="text/javascript" src="${ctx}/js/tipswindown.js"></script>
<script type="text/javascript" src="${ctx }/datepicker/WdatePicker.js"></script>
<!-- DATATABLES CSS END -->
<s:if test="#request.lecturer != null && #request.lecturer.id > 0">
	<h1 class="page-title">内部讲师管理 - 修改</h1>
</s:if>
<s:else>
	<h1 class="page-title">内部讲师管理 - 添加</h1>
</s:else>
<div class="container_12 clearfix leading">
	<div class="side grid_12 leading">
		<form id="post_form" name="post_form" class="form has-validation">
			<s:if test="#request.lecturer != null && #request.lecturer.id > 0">
				<input type="hidden" name="lecturer.id" value="${lecturer.id}" />
			</s:if>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">选择员工 <em>*</em></label>
				<div class="form-input">
					<input id="iput_empIds" type="hidden" name="lecturer.employeeinfoWork.id" value="${lecturer.employeeinfoWork.id}" /> <span
						id="employ_choose_name"
						style="display: inline-block; vertical-align: bottom; border-bottom: solid 1px #ccc; width: 150px; overflow: hidden; text-overflow: ellipsis;">${lecturer.employeeinfoWork.baseId.name}</span>
					<a class="button" style="margin-top: 10px"
						href="javascript:void(0)" onclick="onShowDiv()"><span
						style="background: url(${ctx}/images/img/zoom.png)" class="icon">&nbsp;</span>选择</a>
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">生效日期 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="effective_date" name="effective_date"
						required="required" placeholder="请输入日期" onfocus="WdatePicker({maxDate: '#F{$dp.$D(\'expire_date\')}'})"
						value='<s:date name="#request.lecturer.effectiveDate" format="yyyy-MM-dd"/>' />
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">到期日期 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="expire_date" name="expire_date"
						required="required" placeholder="请输入到期日期" onfocus="WdatePicker({minDate: '#F{$dp.$D(\'effective_date\')}'})"
						value='<s:date name="#request.lecturer.expireDate" format="yyyy-MM-dd"/>' />
				</div>
			</div>
			<div class="clearfix">

				<label for="form-name" class="form-label">主要课程 <em>*</em></label>

				<div class="form-input">
					<input type="text" id="course_title" name="lecturer.courseTitle"
						required="required" placeholder="请输入主要课程" value="${lecturer.courseTitle}"/>

				</div>
			</div>
			<div class="form-action clearfix">

				<button class="button" type="button" onclick="checkForm()">
					<s:if test="#request.lecturer.id > 0">修改</s:if>
					<s:else>添加</s:else>
				</button>
				<button class="button" type="reset">重置</button>
				<a class="button" href="javascript:void(0)"
					onclick="javascript:history.back()"><span
					style="background: url(${ctx}/images/img/arrow_undo.png)"
					class="icon">&nbsp;</span>返回</a>

			</div>
		</form>
	</div>
</div>

<div class="clear"></div>
<script type="text/javascript">
	/**
	 * 选择员工
	 */
    function onShowDiv(){
        //$("#config-popover").css("width", 900);
        tipsWindown("选择员工","url:post?${ctx}/employee/staff_list.xhtml?operation=select&organizationId=${organizationId}","900","350","true","","true","text");
    }
	
  	//员工选择框返回事件
    function onSelectEployee(eid, ename, wid){
        //alert(eid+"----------"+ename+"----------"+wid);
        if(eid == undefined || ename == undefined || wid == undefined){
            return;
        }
        $("#iput_empIds").val(wid);
        $("#employ_choose_name").html(ename);
        /* $.ajax({
            type: 'POST',
            url:"${ctx}/ajax/check_user_work.xhtml",
            data:{"workId":wid},
            dataType:"json",
            success: function(exist){
                if(exist == true || exist == "true"){
                    alert("该员工已添加账号");
                    return;
                }else{
                    $("#work_choose_id").val(wid);
                    $("#employ_choose_name").html(ename);
                    $("#user_name").val(ename);
                    return;
                }
            }
        }); */
    }

	function checkForm() {
		if ($("#iput_empIds").val() == null || $("#iput_empIds").val() == "") {
			alert("请选择员工");
			return;
		}
		
		if ($("#effective_date").val() == null || $("#effective_date").val() == "") {
			alert("请输入生效日期");
			return;
		}
		
		if ($("#expire_date").val() == null || $("#expire_date").val() == "") {
			alert("请输入到期日期");
			return;
		}
		
		if ($("#course_title").val() == null || $("#course_title").val() == "") {
			alert("请输入主要课程");
			return;
		}

		var url = "${ctx}/train/post_lecturer.xhtml";
		$
				.ajax(
						url,
						{
							type : "POST",
							data : $("#post_form").serialize(),
							dataType : "html",
							cache : false,
							success : function(a) {
								alert("提交成功");
								window.location.href = "${ctx}/index.xhtml#train/lecturer_main.xhtml?organizationId=${category.organization.id}";
							},
							error : function(XMLHttpRequest, textStatus,
									errorThrown) {
								alert('提交申请发生异常');
							},
							complete : function() {
							}
						});

	}

	
</script>